package com.hrzyit.whistle.cases.ui.adapter

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Toast
import com.hrzyit.base.ext.onClick
import com.hrzyit.base.ui.adapter.BaseRecyclerViewAdapter
import com.hrzyit.base.widgets.CaseButton
import com.hrzyit.whistle.cases.R
import org.jetbrains.anko.support.v4.toast

/**
 * 案件按钮
 * @author YangWei
 * @date 2019/4/15
 */
class CaseButtonAdapter(context: Context) :
    BaseRecyclerViewAdapter<CaseButton, CaseButtonAdapter.ViewHolder>(context) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(mContext)
            .inflate(R.layout.item_case_button, parent, false)

        return ViewHolder(view)
    }

    /**
     * 绑定视图
     */
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {

        super.onBindViewHolder(holder, position)

        // 上传的图片
        val caseButton = dataList[position]

        val buttonElement = holder.itemView.findViewWithTag<Button>("caseButton")

        // 设置按钮属性
        buttonElement.id = caseButton.id
        buttonElement.text = caseButton.text

    }

    /**
     * 返回数据记录数
     */
    override fun getItemCount(): Int {
       return dataList.size
    }

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}